package com.tledu.ssm01.core;

import com.tledu.ssm01.core.exception.CustomException;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 对所有的controller增强
 * @author Antg
 * @date 2021/8/12  23:06
 */
@ControllerAdvice
public class ExceptionController{
    @ExceptionHandler(CustomException.class)
    public String exceptionHandle(CustomException e, Model model){
        //如果报错
        model.addAttribute("msg", e.getMessage());
        return "error";
    }
}
